package src.ee.ioc.smaug.parser;

import src.ee.ioc.smaug.world.evolution.EnvDescription;

import java.io.File;
/**
 * Writes fsm to xml file
 * 
 * @author Margarita Spichakova
 * 
 */
public class ParameterXMLWriter {
    /**
     * Entiy of XML writer
     */
    static XMLWriter write = new XMLWriter(EnvDescription.ParamXMLfilename);

    
    public static void writeParameters() {

        write.writePreface("1.0", "UTF-8",new File(EnvDescription.parametersdtd).toURI().toString());
        write.writeStylesheet(new File(EnvDescription.parametersxsl).toURI().toString());

        write.openEntryTag("parameters");
        write.closeEntryTag();
        
        writeOneParameter("mutationProb",EnvDescription.mutationProb+"");
        
        writeOneParameter("FFtype",EnvDescription.FFtype.name());
        writeOneParameter("MUTtype",EnvDescription.MUTtype.name());
        writeOneParameter("CROSStype",EnvDescription.CROSStype.name());
        writeOneParameter("SELtype",EnvDescription.SELtype.name());
        
        writeOneParameter("dataFile",EnvDescription.dataFile.getName());
        writeOneParameter("FSMXMLfilename",EnvDescription.FSMXMLfilename);
        writeOneParameter("ParamXMLfilename",EnvDescription.ParamXMLfilename);
        writeOneParameter("LOGfilename",EnvDescription.LOGfilename);
        writeOneParameter("loglevel",EnvDescription.loglevel.getName());
        writeOneParameter("numberOfStates",EnvDescription.numberOfStates+"");
        writeOneParameter("generating",EnvDescription.generating.name());
        writeOneParameter("beingType",EnvDescription.beingType.name());
        writeOneParameter("numberOfGenerations",EnvDescription.numberOfGenerations+"");
        writeOneParameter("sizeOfPopulation",EnvDescription.sizeOfPopulation+"");
        
        
        write.closeEntry("parameters");

        write.closeWriter();

    }
    
    private static void writeOneParameter(String name, String value) {
        write.openEntryTag("parameter");
        write.writeAttribute("name", name);
        write.writeAttribute("pvalue", value);
        write.closeEntryTag();
        write.closeEntry("parameter"); 
    }

    

}
